package com.study.es.test;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

/**
 * @author MI
 * @version 1.0
 * @date 2021/4/24 21:49
 */
public class ESTest_Index_Delete {
    public static void main(String[] args) throws IOException {
        // 创建ES客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 9200, "http"))
        );
        //查看索引信息|http://127.0.0.1:9200/_cat/indices?v
        //查询索引
        final DeleteIndexRequest request = new DeleteIndexRequest("user");
        final AcknowledgedResponse delete = esClient.indices().delete(request, RequestOptions.DEFAULT);
        System.out.println(delete.isAcknowledged());

        // 关闭ES客户端
        esClient.close();
    }
}
